package com.minelx.scriptbuilder.script.attribute.value;

import com.minelx.scriptbuilder.script.IVariable;
import com.minelx.scriptbuilder.script.attribute.function.Params;

public interface IAttribute {

	IAttribute NIL = new IAttribute() {
		@Override
		public String asString() {
			throw new RuntimeException("nil.toString() --- exception");
		}

		@Override
		public String toString() {
			return "IAttribute.NIL";
		}
	};

	String asString();

	default IAttribute execute(Params params) {
		System.out.println("this = " + this);
		throw new UnsupportedOperationException("unsupported operation");
	}

	default void set(String name, IAttribute value) {
		System.out.println("this = " + this);
		throw new UnsupportedOperationException("unsupported operation");
	}

	default IVariable get(String name) {
		System.out.println("this = " + this);
		throw new UnsupportedOperationException("unsupported operation");
	}

	default IAttribute value(String name) {
		return get(name).value();
	}

	default IAttribute value(String name, IAttribute def) {
		IAttribute result = value(name);
		if (result == null)
			return def;
		return result;
	}

	default void belongsTo(IAttribute parent) {
	}

	default boolean isNull() {
		return this == nil();
	}

	static IAttribute nil() {
		return NIL;
	}
}
